package com.KA.controller;


import com.KA.common.R;
import com.KA.dto.ConsumeVo;
import com.KA.dto.InsertMoneyVo;
import com.KA.dto.RefundVo;
import com.KA.dto.checkWalletVo;
import com.KA.entity.UserWallet;
import com.KA.service.UserWalletService;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;


@RestController
@RequestMapping("user")
@Api(tags = "用户钱包控制类")
public class UserWalletController {

    @Autowired
    private UserWalletService userWalletService;

    @ApiOperation(value = "查看钱包余额")
    @PostMapping("/checkWallet")
    public R checkWallet(@RequestBody checkWalletVo checkWalletVo){
        return R.success(userWalletService.checkWallet(checkWalletVo));
    }

    @ApiOperation(value = "钱包充值")
    @PostMapping("/Walletinsert")
    public R Walletinsert(@RequestBody InsertMoneyVo insertMoneyVo){
        return R.success(userWalletService.InsertMoney(insertMoneyVo));
    }

    @ApiOperation(value = "钱包扣钱-消费")
    @PostMapping("/consume")
    public R consume(@RequestBody ConsumeVo consumeVo){
        return R.success(userWalletService.consume(consumeVo));
    }

    @ApiOperation(value = "钱包收钱-退款")
    @PostMapping("/refund")
    public R refund(@RequestBody RefundVo refundVo){
        return R.success(userWalletService.refund(refundVo));
    }


     @ApiOperation(value = "钱包金额重置为0")
    @PostMapping("/remakemoney")
    public R remakemoney(@RequestBody checkWalletVo checkWalletVo){
        UserWallet one = userWalletService.getOne(new LambdaQueryWrapper<UserWallet>().eq(UserWallet::getMobile, checkWalletVo.getMobile()));
        one.setMoney(new BigDecimal(0.00));
        return R.success(userWalletService.updateById(one));
    }



}
